// 颜色选择器
export class ColorPicker {
  onBegin({x: offsetX, y: offsetY}, {button}) {
    let {x, y} = this.global.checkXYPX({x: offsetX, y: offsetY});
    let c_width = this.canvas.width;
    let c_height = this.canvas.height;
    let id = this.ctx.getImageData(0, 0, c_width, c_height);
    let pixel_pos = (y * c_width + x) * 4;
    let r = id.data[pixel_pos + 0];
    let g = id.data[pixel_pos + 1];
    let b = id.data[pixel_pos + 2];
    let a = id.data[pixel_pos + 3];
    const o = button === 0 ? {foregroundColor: `rgba(${r},${g},${b},${a})`} :
      {backgroundColor: `rgba(${r},${g},${b},${a})`};
    this.global.setOption(o);
  }
}